package errcode

import "fmt"

// Status is a return value for calls that don't return other objects.
type Status struct {
	Code         int32  `json:"code,omitempty" protobuf:"varint,6,opt,name=code"`
	ErrorCode    string `json:"error_code,omitempty"`
	ErrorMessage string `json:"error_msg,omitempty"`
	Message      string `json:"message,omitempty" protobuf:"bytes,3,opt,name=message"`
	Reason       string `json:"reason,omitempty" protobuf:"bytes,4,opt,name=reason,casttype=StatusReason"`
	Details      string `json:"details,omitempty" protobuf:"bytes,5,opt,name=details"`
}

// WithMessage set err Message
func (s Status) WithErr(err error) Status {
	s.Message = err.Error()
	return s
}

// WithMessage set err Message
func (s Status) WithMessage(message string) Status {
	s.Message = message
	return s
}

// WithMessagef set err Message according to a format specifier
func (s Status) WithMessagef(format string, args ...interface{}) Status {
	return s.WithMessage(fmt.Sprintf(format, args...))
}

func (s Status) Error() string {
	return fmt.Sprintf("HTTP Code: %d, Reason: %s, ErrorCode: %s,ErrorMessage: %s", int(s.Code), s.Reason, s.ErrorCode, s.ErrorMessage)
}